package com.shaoshaohuo.app.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.shaoshaohuo.app.R;
import com.shaoshaohuo.app.entity.Search_Item_Entity;

import java.util.List;

/**
 * Created by Administrator on 2017/6/8.
 */

public class SearchItemAdapter extends BaseAdapter {

    private Context context;
    private List<Search_Item_Entity.DataBean> dataBeen;

    public SearchItemAdapter(Context context, List<Search_Item_Entity.DataBean> dataBeen) {
        this.context = context;
        this.dataBeen = dataBeen;
    }

    public void setNotify(List<Search_Item_Entity.DataBean> dataBeen) {
        this.dataBeen = dataBeen;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return dataBeen != null ? dataBeen.size() : 0;
    }

    @Override
    public Search_Item_Entity.DataBean getItem(int position) {
        return dataBeen.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        searchItemViewHolder holder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.search_item_textview, parent, false);
            holder = new searchItemViewHolder();
            holder.name = (TextView) convertView.findViewById(R.id.search_item_name);
            convertView.setTag(holder);
        } else {
            holder = (searchItemViewHolder) convertView.getTag();
        }
        holder.name.setText(dataBeen.get(position).getName());
        return convertView;
    }


    class searchItemViewHolder {
        TextView name;
    }
}
